package com.example.mainapp.controller;

import com.example.mapper.UserMapper;
import com.example.mapper.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/users")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping
    public List<User> getAllUsers() {
        return userMapper.selectList(null);
    }

    @PostMapping
    public String addUser(@RequestBody User user) {
        userMapper.insert(user);
        return "User added successfully";
    }

    @GetMapping("/{id}")
    public User getUserById(@PathVariable Long id) {
        return userMapper.selectById(id);
    }
}